import java.awt.*;

public class WriterTest extends Frame {

	/**
	 * 
	 */
	private static final long serialVersionUID = -3351351300203746000L;

	// private SharedObject cpto;
	static String myName;

	static SharedObject c = null;

	public static void main(String argv[]) {
		if (argv.length != 1) {
			System.out.println("java WriterTest <name>");
			return;
		}
		myName = argv[0];

		// initialize the system
		Client.init();

		// look up the IRC object in the name server
		// if not found, create it, and register it in the name server
		Counter cpt = null;
		c = Client.lookup("Counter");
		if (c == null) {
			cpt = new Counter();
			c = Client.create(cpt);
			Client.register("Counter", c);
		}

		while (true) {
			if (Integer.valueOf(myName) > 0) {
				c.lock_write();
				((Counter) (c.obj)).increment(myName);
				c.unlock();
			} else {
				c.lock_write();
				((Counter) (c.obj)).decrement(myName);
				c.unlock();
			}

		}

	}
}
